<template>
<div class="div_main_frame" style="text-align:center;margin:0 auto" align="center">
<div class="fastweb_div_middle" style="width:100%;text-align:center;">
    <h1>自定义实体集</h1>
    <p><span style="line-height:50px;">注意：自定义实体集仅自己可用，用户标识与定制任务的用户标识需保持一致。</span></p>
    <el-form ref="formRef" :model="form" label-width="80px">
    <el-form-item label="名称">
      <el-input v-model="form.name"></el-input>
    </el-form-item>
	
    <el-form-item label="用户标识">
      <el-input v-model="form.user"/>
    </el-form-item>


	<el-form-item label="来源网址">
      <el-input v-model="form.url"/>
    </el-form-item>

	<el-form-item label="集合">
      <el-input v-model="form.entity_set" type="textarea"  :rows="10"/>
    </el-form-item>

    <!--el-form-item-->
      <el-button type="primary" @click="onSubmit">提交</el-button>
    <!--/el-form-item-->
    <p><font color="red"><strong>{{result_message}}</strong></font></p>
  </el-form>

</div>
</div>
<ViewFooter/>
</template>

<script>
import { reactive } from 'vue'
import { ref } from 'vue'
import { getCurrentInstance } from 'vue'
import "@/assets/global.css"
import "@/assets/fastweb.css"
import ViewFooter from '@/components/ViewFooter.vue'

export default {
    name: 'PageAddSuggest',
    components: {
        ViewFooter,
    },
    data() {
        return {
            result_message:''
        };
    },
    setup(){
       const form = reactive({
            name: '',
            user: '',
            url: '',
            entity_set: '',
            });
        
        const host = getCurrentInstance()?.appContext.config.globalProperties.host
        return {form,host};
        
    },
    methods: {
        onSubmit() {
            if (this.form.name === '') {
                alert("实体集名称不能为空");
                return;
            } else {
                if (this.form.user.length < 8) {
                    alert("用户标识长度不能小于8位");
                    return;
                }
            }
            console.log('submit5!' + this.form.name)
            this.result_message = ""
            let data = new FormData();
            data.append("name", this.form.name);
            data.append("url", this.form.url);
            data.append("user", this.form.user);
            data.append("entity_set", this.form.entity_set.replace(/[\n\r]/g,'|'));
            console.log('submit5!,' + this.form.entity_set.replace(/[\n\r]/g,'|'))
            
            var api_url = this.host.concat("/api/entity_data_suggest")
            this.axios.post(api_url, data)
            .then(response => {
                if((response.status != 200) || (response.data.result != 0)){
                this.$message({
                    message: "添加失败",
                    type: "fail"
                });
                return;
                }
                this.result_message = "添加成功"
            })
            .catch(error => alert("添加失败"));
            
        },
    }
};



</script>